package com.novasoftware.novagooglemap.db.builder;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;

import com.novasoftware.novagooglemap.db.DataBaseBuilder;
import com.novasoftware.novagooglemap.db.entity.NovaCategory;

public class NovaCategoryBuilder implements DataBaseBuilder<NovaCategory>  {

	
	private String root;
	
	public String getRoot() {
		return this.root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

	public String table() {
		return "NovaCategory";
	}

	@Override
	public NovaCategory build(Cursor query) {
		int Id = query.getColumnIndex("Id");
		int Name = query.getColumnIndex("Name");
		int ImageId = query.getColumnIndex("ImageId");
		int CaseStudy = query.getColumnIndex("CaseStudy");
		
		NovaCategory novaCategory = new NovaCategory();
		novaCategory.Id = query.getInt(Id);
		novaCategory.ImageId = query.getInt(ImageId);
		novaCategory.Name = query.getString(Name);
		novaCategory.CaseStudy = query.getInt(CaseStudy);
		
		return novaCategory;
	}

	@Override
	public ContentValues deconstruct(NovaCategory entity) {
		ContentValues values = new ContentValues();
		if(entity.Id>0) values.put("Id", entity.Id);
		values.put("Name", entity.Name);
		values.put("CaseStudy", entity.CaseStudy);
		values.put("ImageId", entity.ImageId);
		return values;
	}

	@Override
	public NovaCategory jsonBuild(JSONObject jsonObject) throws JSONException {
		NovaCategory novaCategory = new NovaCategory();
		novaCategory.Id = jsonObject.getInt(root+"Id");
		novaCategory.Name = jsonObject.getString(root+"Name");
		novaCategory.ImageId = jsonObject.getInt(root+"ImageId");
		novaCategory.CaseStudy = jsonObject.getInt(root+"CaseStudy");
		return novaCategory;
	}

}
